using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

//
//  Software written by Rodney Viana 2008
//  Please reach me @ https://blogs.msdn.com/rodneyviana
//

namespace MOSSLoadTest
{
	/// <summary>
	/// Summary description for Form2.
	/// </summary>
	public class LoginForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.TextBox Domain;
		private System.Windows.Forms.TextBox Password;
		private System.Windows.Forms.TextBox UserName;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button3;
        private GroupBox groupBox3;
        private TextBox Server;
        private CheckBox chkCertificate;
        private IContainer components;

		public LoginForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.button2 = new System.Windows.Forms.Button();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.button1 = new System.Windows.Forms.Button();
            this.Domain = new System.Windows.Forms.TextBox();
            this.Password = new System.Windows.Forms.TextBox();
            this.UserName = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.button3 = new System.Windows.Forms.Button();
            this.groupBox3 = new System.Windows.Forms.GroupBox();
            this.chkCertificate = new System.Windows.Forms.CheckBox();
            this.Server = new System.Windows.Forms.TextBox();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox3.SuspendLayout();
            this.SuspendLayout();
            // 
            // button2
            // 
            this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.button2.Location = new System.Drawing.Point(135, 339);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(72, 23);
            this.button2.TabIndex = 4;
            this.button2.Text = "Cancel";
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.button1);
            this.groupBox1.Controls.Add(this.Domain);
            this.groupBox1.Controls.Add(this.Password);
            this.groupBox1.Controls.Add(this.UserName);
            this.groupBox1.Controls.Add(this.label3);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Location = new System.Drawing.Point(7, 158);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(312, 168);
            this.groupBox1.TabIndex = 8;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Use This User";
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(128, 136);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(72, 24);
            this.button1.TabIndex = 14;
            this.button1.Text = "Login";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // Domain
            // 
            this.Domain.Location = new System.Drawing.Point(132, 93);
            this.Domain.Name = "Domain";
            this.Domain.Size = new System.Drawing.Size(160, 20);
            this.Domain.TabIndex = 13;
            // 
            // Password
            // 
            this.Password.Location = new System.Drawing.Point(132, 61);
            this.Password.Name = "Password";
            this.Password.PasswordChar = '*';
            this.Password.Size = new System.Drawing.Size(160, 20);
            this.Password.TabIndex = 12;
            // 
            // UserName
            // 
            this.UserName.Location = new System.Drawing.Point(132, 29);
            this.UserName.Name = "UserName";
            this.UserName.Size = new System.Drawing.Size(160, 20);
            this.UserName.TabIndex = 11;
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(20, 93);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(100, 23);
            this.label3.TabIndex = 10;
            this.label3.Text = "Domain:";
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(20, 61);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(100, 23);
            this.label2.TabIndex = 9;
            this.label2.Text = "Password:";
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(20, 29);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(100, 23);
            this.label1.TabIndex = 8;
            this.label1.Text = "User Name:";
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.button3);
            this.groupBox2.Location = new System.Drawing.Point(7, 86);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(312, 64);
            this.groupBox2.TabIndex = 9;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Current User";
            // 
            // button3
            // 
            this.button3.Location = new System.Drawing.Point(128, 24);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(72, 24);
            this.button3.TabIndex = 15;
            this.button3.Text = "Login";
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // groupBox3
            // 
            this.groupBox3.Controls.Add(this.chkCertificate);
            this.groupBox3.Controls.Add(this.Server);
            this.groupBox3.Location = new System.Drawing.Point(8, 8);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new System.Drawing.Size(311, 76);
            this.groupBox3.TabIndex = 10;
            this.groupBox3.TabStop = false;
            this.groupBox3.Text = " Server ";
            // 
            // chkCertificate
            // 
            this.chkCertificate.AutoSize = true;
            this.chkCertificate.Location = new System.Drawing.Point(23, 44);
            this.chkCertificate.Name = "chkCertificate";
            this.chkCertificate.Size = new System.Drawing.Size(163, 17);
            this.chkCertificate.TabIndex = 1;
            this.chkCertificate.Text = "I want to choose a certificate";
            this.chkCertificate.UseVisualStyleBackColor = true;
            // 
            // Server
            // 
            this.Server.Location = new System.Drawing.Point(23, 18);
            this.Server.Name = "Server";
            this.Server.Size = new System.Drawing.Size(269, 20);
            this.Server.TabIndex = 0;
            // 
            // LoginForm
            // 
            this.AcceptButton = this.button2;
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.BackColor = System.Drawing.Color.WhiteSmoke;
            this.CancelButton = this.button2;
            this.ClientSize = new System.Drawing.Size(338, 375);
            this.ControlBox = false;
            this.Controls.Add(this.groupBox3);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.button2);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "LoginForm";
            this.Text = "Login";
            this.Load += new System.EventHandler(this.LoginForm_Load);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox3.ResumeLayout(false);
            this.groupBox3.PerformLayout();
            this.ResumeLayout(false);

		}
		#endregion

        private string credentialUserName = "";

        public string CredentialUserName
        {
            get { return credentialUserName; }
            set { credentialUserName = value; }
        }
        private string credentialPassword = "";

        public string CredentialPassword
        {
            get { return credentialPassword; }
            set { credentialPassword = value; }
        }
        private string credentialDomain = "";

        public string CredentialDomain
        {
            get { return credentialDomain; }
            set { credentialDomain = value; }
        }
        private bool useCurrentUser = false;

        public bool UseCurrentUser
        {
            get { return useCurrentUser; }
            set { useCurrentUser = value; }
        }
        private string urlServer = "";

        public string UrlServer
        {
            get { return urlServer; }
            set { urlServer = value; }
        }



		public bool Canceled = false;
		private void button1_Click(object sender, System.EventArgs e)
		{
            if (this.chkCertificate.Checked)
                Certificate.SelectCertificate();
			Canceled = false;
			useCurrentUser = false;
			credentialUserName = this.UserName.Text;
			credentialPassword = this.Password.Text;
			credentialDomain = this.Domain.Text;
            urlServer = this.Server.Text;
			this.Close();
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			Canceled = true;
			this.Close();
		}

		private void LoginForm_Load(object sender, System.EventArgs e)
		{
            if (CredentialUserName != String.Empty)
            {
                UserName.Text = credentialUserName;
                Password.Text = credentialPassword;
                Domain.Text = credentialDomain;
            }
            if (urlServer != String.Empty)
            {
                Server.Text = urlServer;

            }
			UserName.Focus();
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
            if(this.chkCertificate.Checked)
                Certificate.SelectCertificate();
			Canceled = false;
			UseCurrentUser = true;
			CredentialUserName = this.UserName.Text;
			CredentialPassword = this.Password.Text;
			CredentialDomain = this.Domain.Text;
            urlServer = this.Server.Text;
			this.Close();		
		}

        private void timer1_Tick(object sender, EventArgs e)
        {

        }

	}
}
